package com.gary.security.service.impl;

import java.util.List;

import com.gary.core.service.DefaultServiceImpl;
import com.gary.security.model.UserInfo;
import com.gary.security.model.resource.Resource;
import com.gary.security.repository.AuthenticationRepository;
import com.gary.security.service.AuthenticationService;

import org.springframework.security.userdetails.UserDetails;


/**
 * 借用hibernate获得权限数据.
 */
public class HibernateAuthenticationServiceImpl extends DefaultServiceImpl<UserInfo>
    implements AuthenticationService {
    /**
     * 角色前缀.
     */
    private String rolePrefix = "";

    /**
     * @param rolePrefix 角色前缀.
     */
    public void setRolePrefix(String rolePrefix) {
        this.rolePrefix = rolePrefix;
    }
    
    private AuthenticationRepository repos;
    
	public void setRepos(AuthenticationRepository repos) {
		this.repos = repos;
	}

	/**
     * 获取所有用户实例.
     *
     * @see com.AuthenticationRepository.security.service.AuthenticationService#getUsers()
     * @return List
     */
    public List<UserDetails> getUsers() {
        return repos.getUsers(rolePrefix);
    }

    /**
     * 获取所有资源实例.
     *
     * @see com.AuthenticationRepository.security.service.AuthenticationService#getResources()
     * @return List
     */
    public List<Resource> getResources() {
        return repos.getResources(rolePrefix);
    }

        
}
